<%@ page contentType="text/html;charset=UTF-8"%>
<%@ include file="/WEB-INF/views/include/taglib.jsp"%>
<%
String htmlData = request.getParameter("content1") != null ? request.getParameter("content1") : "";
%>
<html>
<head>
<title>合同模板编辑</title>
<meta http-equiv="Content-Type" content="text/html;charset=utf-8" />
<%-- <script type="text/javascript" charset="utf-8"src="${staticPath}/lib/ueditor1_3_6-utf8-jsp/ueditor.config.js"></script> --%>
<%-- <script type="text/javascript" charset="utf-8"src="${staticPath}/lib/ueditor1_3_6-utf8-jsp/ueditor.all.min.js"></script> --%>
<!-- <script type="text/javascript" charset="utf-8" src="lang/zh-cn/zh-cn.js"></script> -->

<script type="text/javascript" charset="utf-8" src="${staticPath}/lib/kindeditor/kindeditor.js"></script>
<script src="${staticPath}/lib/jquery/1.9.1/jquery-1.9.1.min.js" type="text/javascript"></script>
<script src="${staticPath}/js/jquery-migrate-1.1.1.js"></script> 

<style type="text/css">
.clear {
	clear: both;
}
</style>

</head>
<body>
	<div>
		<textarea id="content" name="content" cols="100" rows="8" style="width:1024px;height:550px;visibility:hidden;">${template.templateContent}</textarea>
	</div>
	<div>
		<input type="text" value="${template.id}" id="id" style="display: none;" /> 
		<input type="text" value="${template.templateName}" id="templateName" style="display: none;" /> 
	</div>
	<br/>
	<div id="btns">
		<div>
			<button onclick="history.go(-1)">返回</button>
			<button onclick="showAddTemplatePage()">下一步</button>
		</div>
	</div>
</body>
<script type="text/javascript">
	
	KE.show({
		id : 'content',
		imageUploadJson : '${staticPath}/lib/kindeditor/jsp/upload_json.jsp',
		fileManagerJson : '${staticPath}/lib/kindeditor/jsp/file_manager_json.jsp',
		allowFileManager : true,
		afterCreate : function(id) {
			KE.event.ctrl(document, 13, function() {
				KE.util.setData(id);
				document.forms['example'].submit();
			});
			KE.event.ctrl(KE.g[id].iframeDoc, 13, function() {
				KE.util.setData(id);
				document.forms['example'].submit();
			});
		}
	});

// 	UE.getEditor('editor');
// 	setTimeout('setContent()', 300);
// 	function setContent(isAppendTo) {
// 		var content = '${template.templateContent}';
// 		UE.getEditor('editor').setContent(content, isAppendTo);
// 	}

	function addOrUpdate() {
		var content = $("#content").val();
		var id = document.getElementById("id").value;
		var templateName = document.getElementById("templateName").value;
		post('${contextPath}/biz/contract/template/addOrUpdate', {
			templateContent : content,
			id : id,
			templateName : templateName
		});
	}
	function showAddTemplatePage() {
		var content = $("#content").val();
		var id = document.getElementById("id").value;
		var templateName = document.getElementById("templateName").value;
		post('${contextPath}/biz/contract/template/showAddPage', {
			id : id,
			templateContent : content,
			templateName : templateName
		});
	}
	function post(URL, PARAMS) { //post提交
		var temp = document.createElement("form");
		temp.action = URL;
		temp.method = "post";
		temp.style.display = "none";
		for ( var x in PARAMS) {
			var opt = document.createElement("textarea");
			opt.name = x;
			opt.value = PARAMS[x];
			temp.appendChild(opt);
		}
		document.body.appendChild(temp);
		temp.submit();
		return temp;
	}

</script>

</html>